import axios from "../../utils/axios"
import dayjs from "dayjs"
Component({
  options: {
    addGlobalClass: true,
  },
  data: {
    list:[],
    active:"3"
  },
  attached(){
    this.getList();
  },
  methods:{
    onTabsChange(event) {
      this.getList(event.detail.value)
      this.setData({
        active:event.detail.value
      })
    },

    onTabsClick(event) {
      // console.log(`Click tab, tab-panel value is ${event.detail.value}.`);
    },

    toPhone(e){
      wx.makePhoneCall({
        phoneNumber: e.currentTarget.dataset.u
      })
    },
    getList(status){
      this.setData({
        list:[]
      })
      wx.showLoading({
        title: '加载中...',
      })
      axios.get("/app/orderList",{
        current:1,
        pageSize:999,
        status:status || this.data.active,
        companyId:wx.getStorageSync('company_id'),
        type:1
      }).then(res=>{
        wx.hideLoading()
        if(res.data?.[0]?.status !== this.data.active*1){
          // this.setData({
          //   list:[]
          // })
          return;
        }
        this.setData({
          list:res.data.map(item=>{
            const {phone,remark,dpName} = JSON.parse(item.remark ||"{}")
            return {
              ...item,
              timer:dayjs(item.startTime).format("YYYY-MM-DD HH:mm")+" - "+ dayjs(item.endTime).format("HH:mm"),
              statusText:this.getStatus(item.status)
            }
          })
        })
      })
    },
    getStatus(status){
      const orderStatusList = ["待付款","支付成功","消费中","已完成","自动取消","已取消"].map((item,key)=>({label:item,value:key+1}))
      return orderStatusList.find(item=>item.value === status).label;
    },
  },
  
  lifetimes:{

  }
})